<?php

	class Shop_brandModel extends Model{


		public $table='shop_brand';

		public $validate = array(
			// array('bname','nonull','品牌名称不能为空',2,3),
			// //？排序的正则验证怎么写
			// array('sort','regexp:/^\d{1,255}$/','请填写的整数在1-255之间',2,3),
			);

		public function add_data(){
			//如果自动验证不成功返回否
			if (!$this->create()) return false;
			//上传的方法
			$upload = new upload();
			$uploadData = $upload->upload();
			// p($uploadData);die;
			$data = array(
				'bname' =>Q('post.bname'),
				'sort'  =>Q('post.sort'),
				'logo'=>$uploadData[0]['path'],
				'tubiao'=>$uploadData[1]['path'],
				'is_hot' =>Q('post.is_hot'),

				);

			return $this->add($data);	
			
		}


		public function edit_data($bid){

			if (!$this->create()) {
				return false;
			}

			$upload = new upload();
			$uploadData = $upload->upload();
			$data = array(

				'bid'     => $bid,
				'bname'   => Q('post.bname'),
				'sort'    => Q('post.sort'),
				'is_hot'  => Q('post.is_hot'),

				);

			if (empty($uploadData)) {
				
				$data['logo']='';
				$data['tubiao']='';
			}else{
				$data['logo']=$uploadData[0]['path'];
				$data['tubiao']=$uploadData[1]['path'];
			}

			return $this->update($data);
		}
	}












?>